package edu.sctu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
    String url = "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC";
    String root = "root";
    String password ="123456";
    String  driver = "com.mysql.jdbc.Driver";

    //获取数据库连接
    public Connection getConnection() throws ClassNotFoundException, SQLException {

        Class.forName(driver);
        Connection connection =null;
        connection =  DriverManager.getConnection(url,root,password);
        return connection;
    }

    //关闭数据库连接
    public void closeConnection(Connection connection) throws SQLException {
        while (connection != null){
            connection.close();
        }
    }


}

